import {defineStore} from 'pinia';
import {getMusicLyric} from "@/request/api/detailList";

export const infoStore = defineStore({//需要注意的是，defineStore返回的是一个回调方法
    id: 'info',//test是该状态管理的唯一标志也可以使用defineStore(id,{});的形式
    state() {
        return {
            // 存储播放歌曲信息
            playListInfo: [{
                "name": "街上的宝剑",
                "id": 1979732476,
                "ar": [
                    {
                        "id": 29939584,
                        "name": "FAC-D12",
                        "tns": [],
                        "alias": []
                    }
                ],
                "al": {
                    "id": 151231364,
                    "name": "街上的宝剑",
                    "picUrl": "https://p1.music.126.net/POD2fHnKWpOJa13YXXQBTg==/109951167856845841.jpg",
                    "pic_str": "109951167856845841",
                    "pic": 109951167856845840
                },
            }],
            playListIndex: 0,// 默认下标0
            btnShow: true, // 切换播放\暂停按钮  true显示播放按钮
            detailShow: false, // 歌曲详情页显示
            musicLyric: {}, // 歌词信息
            lyricShow: false, // 显示歌词
            currentTime: 0, // 当前时间
            duration: 0, // 当前歌曲时长
            musicMin: '0',
            musicSec: '0',
            isLogin: false,
            isFooterShow: true
        }
    },
    getters: {
        testGetters() {
            return this.name + '...';//直接利用this便能够获取到里面的内容不需要使用state中间对象
        }
    },
    actions: {
        updateBtnShow: function (value) {
            this.btnShow = value
        },
        updatePlayListInfo: function (value) {
            this.playListInfo = value
        },
        updatePlayListIndex: function (value) {
            this.playListIndex = value
        },
        updateDetailShow: function () {
            this.detailShow = !this.detailShow
        },
        updateMusicLyric: function (value) {
            this.musicLyric = value
        },
        updateLyricShow: function () {
            this.lyricShow = !this.lyricShow
        },
        updateCurrentTime: function (value) {
            this.currentTime = value
            // console.log(this.currentTime)
        },
        getLyric: async function (value) {
            let res = await getMusicLyric(value)
            this.updateMusicLyric(res)
        },
        updateMusicMin: function (value) {
            this.musicMin = value
        },
        updateMusicSec: function (value) {
            this.musicSec = value
        },
        updateDuration: function (value) {
            this.duration = value
            let min
            let sec
            if (value / 60 < 10) {
                min = '0' + parseInt(value / 60).toString()
            } else min = parseInt(value / 60).toString()
            this.updateMusicMin(min)
            if (value % 60 < 10) {
                sec = '0' + parseInt(value % 60).toString()
            } else sec = parseInt(value % 60).toString()
            this.updateMusicSec(sec)
            // console.log(this.duration, this.musicMin, this.musicSec)
        },
        updateIsLogin: function (value) {
            this.isLogin = value
        },
        updateIsFooterShow: function (value) {
            this.isFooterShow = value
        }
    }

})